package guicommon.session;

import guicommon.Body;
import guicommon.Header;
import guicommon.Message;
import java.nio.CharBuffer;

public class ErrorMessage extends Message {

    public static final Integer ID = 2;

    public static final String MESSAGE = "message";

    ErrorMessage(Header header, CharBuffer buffer) {
        super(header, buffer);
    }

    public ErrorMessage(String msg) {        
        super(Header.FromType(ErrorMessage.class, ID));
        SetErrorMessage(msg);
    }

    @Override
    protected void ParseBody(CharBuffer charBuffer) {
        String msg = charBuffer.toString().split("=")[1];
        AddParseBodyField(MESSAGE, msg);
    }

    private void SetErrorMessage(String message) {
        SetBodyField(MESSAGE, message);
    }
}
